﻿

class Link extends MovieClip {

	private var middleFrame:Number;
	private var URL:String;
	private var target:String;
	
	function Link() {
		middleFrame = 24;
		URL = null;
		target = null;
	}
	
	function setURL(u:String, t:String):Void {
		URL = u;
		target = (t==null ? "_self" : t);
	}

	function onRelease():Void {
		if(URL != null) {
			getURL(URL, target);
		}
		else {
			Toolset.alert(this, "no hyperlink set");
		}
	}

	function onRollOver():Void {
		if(_currentframe > middleFrame) {
			var shift = _currentframe - middleFrame;
			var eqFrame = Math.round(middleFrame - shift/2);
			if(eqFrame == 1) {
				eqFrame++;
			}
			gotoAndPlay(eqFrame);
		}
		else {
			play();
		}
	}
	
	function onRollOut():Void {
		if(_currentframe < middleFrame) {
			var shift = middleFrame - _currentframe;
			var eqFrame = Math.round(middleFrame + shift*2);
			gotoAndPlay(eqFrame);
		}
		else {
			play();
		}
	}
}